//
//  gyromanagerApp.swift
//  gyromanager
//
//  Created by Shengbo Fan on 2025/9/15.
//

import SwiftUI

@main
struct gyromanagerApp: App {
    @StateObject private var sensorRecorder = SensorRecorder()
    
    var body: some Scene {
        WindowGroup {
            MainView()
                .environmentObject(sensorRecorder)
                .onAppear {
                    // 在应用启动时请求网络权限
                    requestNetworkPermission()
                    // 请求通知权限并安排工作日 11:59 午餐提醒
                    NotificationService.requestAuthorizationAndScheduleLunchReminders()
                }
        }
    }
    
    /// 发起一个简单的网络请求以触发网络权限弹窗
    private func requestNetworkPermission() {
        guard let url = URL(string: "https://www.apple.com") else { return }
        
        let task = URLSession.shared.dataTask(with: url) { _, _, _ in
            // 不需要处理结果，只是为了触发网络权限请求
            print("✅ [App] 网络权限已请求")
        }
        task.resume()
    }
}
